package resolver

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.

import (
	"context"
	"errors"
	"fmt"
	"strings"

	"mall/service/wpgql/api/internal/graph/model"
	"mall/service/wpgql/api/internal/graph/util"
)

func (r *queryResolver) Node(ctx context.Context, id *string) (model.Node, error) { ////
	if id == nil {
		return nil, errors.New("could not get id")
	}

	splitID := strings.SplitN(*id, "-", 2)
	if len(splitID) != 2 {
		return nil, errors.New("could not parse id")
	}

	model := splitID[0]
	switch model {
	case util.RpcEntityNames.ForumComment:
		return r.ForumComment(ctx, *id)
	case "ForumCommentLike":
		return r.ForumCommentLike(ctx, *id)
	case util.RpcEntityNames.ForumForum:
		return r.ForumForum(ctx, *id)
	case util.RpcEntityNames.ForumFriendship: // 作用存疑
		return r.ForumFriendship(ctx, *id)
	case "ForumLike": // 作用存疑
		return r.ForumLike(ctx, *id)
	case util.RpcEntityNames.ForumMediaItem:
		return r.ForumMediaItem(ctx, *id)
	case util.RpcEntityNames.ForumPost:
		return r.ForumPost(ctx, *id)
	case util.RpcEntityNames.ForumTopic:
		return r.ForumTopic(ctx, *id)
	case util.RpcEntityNames.ForumUser:
		return r.ForumUser(ctx, *id)
	default:
		return nil, errors.New("could not find corresponding model for id")
	}
}

func (r *queryResolver) NodeByURI(ctx context.Context, uri string) (model.UniformResourceIdentifiable, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) Revisions(ctx context.Context, first *int, last *int, after *string, before *string, where *model.RootQueryToContentRevisionUnionConnectionWhereArgs) (*model.RootQueryToContentRevisionUnionConnection, error) {
	panic(fmt.Errorf("not implemented"))
}
